{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "## Define model and tools for the graph"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "c1346b9a12395dde"
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "from langchain_core.tools import tool\n",
    "from typing import Literal\n",
    "import os\n",
    "from langchain_openai import ChatOpenAI\n",
    "from langgraph.checkpoint.memory import MemorySaver\n",
    "import uuid\n",
    "from langgraph.store.base import BaseStore\n",
    "from langchain_core.runnables import RunnableConfig\n",
    "from dotenv import load_dotenv\n",
    "from langgraph.constants import START\n",
    "from langgraph.graph import StateGraph, MessagesState\n",
    "\n",
    "load_dotenv()\n",
    "\n",
    "llm = ChatOpenAI(\n",
    "    openai_api_key=os.getenv(\"DASHSCOPE_API_KEY\"),\n",
    "    openai_api_base=\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n",
    "    model_name=\"qwen-max\",\n",
    "    temperature=0,\n",
    ")\n",
    "\n",
    "@tool\n",
    "def get_weather(city: Literal[\"ync\", \"sf\"]):\n",
    "    \"\"\"Use this to get weather information.\"\"\"\n",
    "    if city == \"nyc\":\n",
    "        return \"It might be cloudy in nyc\"\n",
    "    elif city == \"sf\":\n",
    "        return \"It's always sunny in sf\"\n",
    "    else:\n",
    "        raise AssertionError(\"Unknown city\")\n",
    "\n",
    "tools = [get_weather]\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-11-07T06:12:13.292032Z",
     "start_time": "2024-11-07T06:12:11.290745Z"
    }
   },
   "id": "bbfc666df0b93b24",
   "execution_count": 1
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Use sync connection\n",
    "\n",
    "https://langchain-ai.github.io/langgraph/how-tos/persistence_postgres/#with-a-connection-pool"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "ba67a78344f3b65"
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Use async connection\n"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "fd15d5b798eabfed"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
